import os
import sys
import shutil

path = r'C:\\Users\\zm\\Downloads\\Note'
path_image = r'C:\\Users\\zm\\Downloads\\NoteNew\\img'
path_md = r'C:\\Users\\zm\\Downloads\\NoteNew'



if not os.path.exists(path_image):
    os.makedirs(path_image)

if not os.path.exists(path_md):
    os.makedirs(path_md)


count = 0
img = []
du = []

for root,dirs,files in os.walk(path):
    
    for f in files:
        if root == 'path_image':
            break

        if f.endswith(".md"):
            count += 1
            d = f[3:]
            fn ="{}-{}".format(str(count).zfill(4),d)
            shutil.copy(root+"\\"+f, path_md+"\\"+fn)
        else:
            if f in img:
                print(root)
                raise Exception("文件名重复")
            else:
                img.append(f)
                shutil.copy(root+"\\"+f, path_image+"\\"+f)